﻿using Kaleido.Util.Lang;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace Kaleido.Util.Lang
{
    public class TestDynamic : CastedBase
    {

        public static Delegate _function1 = new Func<object, object>((i) => new { name = i });
        public static Delegate _function2 = new Func<object, object, object>((i, j) => new { });
        public static Delegate _function3 = new Func<object, object, object, object>((i, j, k) => new { });
        public static Delegate _function4 = new Func<object, object, object, object, object>((i, j, k, l) => new { });
        public static Delegate _function5 = new Func<object, object, object, object, object, object>((i, j, k, l, m) => new { });
        public static Delegate _function6 = new Func<object, object, object, object, object, object, object>((i, j, k, l, m, n) => new { });

        public TestDynamic(Dynamic obj)
            : base(obj)
        {
        }

        public void Init()
        {
            ////need to be in the correct project to work.
            //DynamicObj.MemberStore.Attach("function1", _function1);
            //DynamicObj.MemberStore.Attach("function2", _function2);
            //DynamicObj.MemberStore.Attach("function3", _function3);
            //DynamicObj.MemberStore.Attach("function4", _function4);
            //DynamicObj.MemberStore.Attach("function5", _function5);
            //DynamicObj.MemberStore.Attach("function6", _function6);
        }

        public object function1(object i)
        {
            var methodBase = MethodBase.GetCurrentMethod();
            var func = this.GetFunc(methodBase);
            return (object)func.DynamicInvoke(i);
        }


        public object function2(object i, object j)
        {
            var methodBase = MethodBase.GetCurrentMethod();
            var func = this.GetFunc(methodBase);
            return (object)func.DynamicInvoke(i, j);
        }

        public object function3(object i, object j, object k)
        {
            var methodBase = MethodBase.GetCurrentMethod();
            var func = this.GetFunc(methodBase);
            return (object)func.DynamicInvoke(i, j, k);
        }

        public object function4(object i, object j, object k, object l)
        {
            var methodBase = MethodBase.GetCurrentMethod();
            var func = this.GetFunc(methodBase);
            return (object)func.DynamicInvoke(i, j, k, l);
        }

        public object function5(object i, object j, object k, object l, object m)
        {
            var methodBase = MethodBase.GetCurrentMethod();
            var func = this.GetFunc(methodBase);
            return (object)func.DynamicInvoke(i, j, k, l, m);
        }

        public object function6(object i, object j, object k, object l, object m, object n)
        {
            var methodBase = MethodBase.GetCurrentMethod();
            var func = this.GetFunc(methodBase);
            return (object)func.DynamicInvoke(i, j, k, l, m, n);
        }
    }
}
